package cn.cloudplug.friendsrecommend.adapter;

import java.util.List;

import cn.cloudplug.friendsrecommend.util.ViewHolder;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public abstract class MyAdapter<T> extends BaseAdapter {
	protected int layoutId;
	protected Context context;
	protected List<T> data;
	protected LayoutInflater inflater;
	public MyAdapter(Context context,List<T> data,int layoutId){
		this.context=context;
		this.data=data;
		this.layoutId=layoutId;
		inflater=LayoutInflater.from(context);
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return data.size();
	}

	@Override
	public T getItem(int position) {
		// TODO Auto-generated method stub
		return data.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent){
		ViewHolder holder=ViewHolder.get(context, parent, layoutId, position, convertView);
		convert(holder,getItem(position));
		return holder.getConvertView();
	}
	public abstract void convert(ViewHolder holder,T t);
}
